#include"os_constant.h"

extern "C" void open_page_mechanism()
{
    //页目录表指针
    int* directory = (int*)PAGE_DIRECTORY;
    //线性地址0-4MB对应的页表
    int* page = (int*)(PAGE_DIRECTORY+PAGE_SIZE);

    int entryNum = PAGE_SIZE/sizeof(int);
    for(int i=0;i<entryNum;i++)
    {
        directory[i]=0; //初始化页目录表
        page[i]=0;      //初始化线性地址0-4MB对应的页表
    }

    int address = 0;
    //将线性地址0-1MB恒等映射到物理地址0-1MB
    for(int i=0; i<256; i++)
    {
        // U/S=1,R/W=1,P=1
        page[i] = address | 0x7;
        address += PAGE_SIZE;
    }

    //初始化页目录项
    //0-1MB
    directory[0] = ((int)page) | 0x07;
    //3GB的内核空间
    directory[768] = directory[0];
    //最后一个页目录项指向页目录表
    directory[1023] = ((int)directory) | 0x7;
}